Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Adding OpenAPI v3.0 Support #57

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open

[WIP] Adding OpenAPI v3.0 Support #57

wants to merge 6 commits into from

Conversation

philsturgeon
Copy link

@philsturgeon philsturgeon commented Jul 20, 2018

Seeing as Swagger Parser supports OpenAPI v3.0 it should be pretty much free to upgrade.

It's taking a bit of work but I'll get there.

@@ -5,9 +5,15 @@ const Randexp = require('randexp').randexp;

const mock = (schema, useExample) => {
let mock;

// Parameters and responses live inside the schema keyword now
if (schema.schema) {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm pretty proud of this one. 😅

@philsturgeon philsturgeon changed the title Attempting to upgrade to OpenAPI v3.0 [WIP] Adding OpenAPI v3.0 Support Jul 20, 2018
@philsturgeon
Copy link
Author

Actually, im going to have to leave this right here I'm affraid. My approach to mocking for now is going to be trying to help Prism upgrade to v3.0.

If you'd like to continue this, there is a great article on v3.0 differences.

https://dev.to/mikeralphson/comparing-openapiswagger-20-and-300-rc1

A lot of these test failures are down to your tests asserting very v2.0 specific things, so changing this is mostly changing the tests. The collectionFormat stuff is tricky too, as that changed a lot. No more explicit delimeters, and there's a whole matrix of options to support, and objects should be supported instead of just arrays. That's about where I left this work on Friday.

https://swagger.io/specification/#style-values

Best of luck to ya!

const Format = require('./format');
const Randexp = require('randexp').randexp;

const mock = (node, useExample) => {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Notice I'm calling this node instead of schema, as the schema is actually node.schema now.

screen shot 2018-07-24 at 10 57 43 am


if (schema) {
let type = schema.type || findType(schema);
let example = schema.examples || schema.example || schema.default;
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added default as an example, which the spec says can be used if no examples exist.

This schema.example || ... might give funny results if example is 0 or false.

@@ -34,7 +34,7 @@
"chance": "^1.0.3",
"moment": "^2.13.0",
"randexp": "^0.4.2",
"swagger-parser": "^3.4.1"
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This bit gets you a version of Swagger Parser which understands OpenAPI v3.0.

@@ -13,7 +13,7 @@ describe('Parameter Mock generator', () => {
path: '/store/order/{orderId}',
operation: 'get'
}, (err, mock) => {
Assert.ok(!err, 'No error');
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will help you actually see the errors that are coming in, making debugging a lot easier.

Also should.js is a fantastic assertions library. Check out oas-kit and Speccy for loads of actual usage examples with OAS world.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant